package com.cy.milktea.pojo;


import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
public class Order implements Serializable {

    private static final long serialVersionUID = 6119794400754667352L;

    private Integer id;  //-------------------->索引
    private String orderID;  //---------------->订单号
    private Integer orderStatus;  //----------->订单状态 0:提交成功 1:支付成功 2:已完成 3:已取消 4:已过期
    private Integer payStatus;  //------------->支付状态 0:待支付 1:已支付 2:已取消 3:支付失败
    private String consumerId;  //------------->顾客编号
    private Long cost = 0L;  //---------------->总价格
    private Long points;  //------------------->订单积分
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    private Date toOrderTime;  //-------------->下单时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    private Date payTime;  //------------------>支付时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    private Date receiveTime;  //-------------->收货时间

    private OrderInfo orderInfo;  //----------->订单详情信息

    private boolean isTotalCost = true;  //---->已经计算价格为false,未计算价格为true

    private Bill bill;  //--------------------->用于微信支付


    //生成订单描述
    public void createDrinkDesc(){
        List<Goods> goodsList = orderInfo.getGoodsList();
        for (Goods goods : goodsList){
            goods.createDrinkDesc();
        }
    }

    //计算总价格
    public Long totalCost() {
        //防止重复计算
        if (isTotalCost) {
            isTotalCost = false;
            List<Goods> goodsList = orderInfo.getGoodsList();
            for (Goods goods : goodsList) {
                cost += goods.totalCost();
            }
        }
        return cost;
    }



}
